package com.learning.db.pretreatment;

import com.google.common.base.Joiner;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * ClassName: PretreatmentDataBean
 * Description: 预处理数据实体
 * <p>
 * 个人编号
 * 医疗结算事件id
 * 人员类别
 * 就诊医院编号
 * 结算来源
 * 就诊方式
 * 结算日期
 * 自费金额
 * 自理金额
 * 自负金额
 * 其中救助基金（自费）
 * 明细汇总求和
 * 合规自费金额
 * 自负+合规自费金额
 * <p>
 * Date: 2018/3/30 10:26 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Setter
@Getter
@EqualsAndHashCode
public class PretreatmentDataBean implements WritableComparable<PretreatmentDataBean> {


    private static final Joiner JOINER = Joiner.on("|");

    /**
     * 个人编号
     */
    private String aac999;
    /**
     * 医疗结算事件id
     */
    private String cka009;
    /**
     * 人员类别
     */
    private String bae041;
    /**
     * 就诊医院编号
     */
    private String aaz107;
    /**
     * 结算来源
     */
    private String cke480;
    /**
     * 就诊方式
     */
    private String aka078;
    /**
     * 结算日期
     */
    private long cke011;
    /**
     * 自费金额
     */
    private String ake051;
    /**
     * 自理金额
     */
    private String ckc077;
    /**
     * 自负金额
     */
    private double akc254;
    /**
     * 其中救助基金（自费）
     */
    private String ckc345;
    /**
     * 明细汇总求和
     */
    private String detailSum;
    /**
     * 合规自费金额
     */
    private double complianceOwnExpense;
    /**
     * 自负+合规自费金额
     */
    private double akc254AddComplianceOwnExpense;

    /**
     * 区分本期数据与往期数据
     * 1-本期 0-往期
     */
    private int flag;

    /**
     * 自负-赔付
     */
    private double akc254Compensate;
    /**
     * 自负和合规自费费用-赔付
     */
    private double akc254AddCOECompensate;

    /**
     * 自负累计
     */
    private double sumAkc254;

    /**
     * 合规自费累计
     */
    private double sumComplianceOwnExpense;

    /**
     * 自负+合规自费 累计
     */
    private double sumAkc254AddComplianceOwnExpense;


    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(this.aac999);
        out.writeUTF(this.cka009);
        out.writeUTF(this.bae041);
        out.writeUTF(this.aaz107);
        out.writeUTF(this.cke480);

        out.writeUTF(this.aka078);
        out.writeLong(this.cke011);
        out.writeUTF(this.ake051);
        out.writeUTF(this.ckc077);
        out.writeDouble(this.akc254);

        out.writeUTF(this.ckc345);
        out.writeUTF(this.detailSum);
        out.writeDouble(this.complianceOwnExpense);
        out.writeDouble(this.akc254AddComplianceOwnExpense);
        out.writeInt(this.flag);
    }

    @Override
    public void readFields(DataInput in) throws IOException {

        this.aac999 = in.readUTF();
        this.cka009 = in.readUTF();
        this.bae041 = in.readUTF();
        this.aaz107 = in.readUTF();
        this.cke480 = in.readUTF();

        this.aka078 = in.readUTF();
        this.cke011 = in.readLong();
        this.ake051 = in.readUTF();
        this.ckc077 = in.readUTF();
        this.akc254 = in.readDouble();

        this.ckc345 = in.readUTF();
        this.detailSum = in.readUTF();
        this.complianceOwnExpense = in.readDouble();
        this.akc254AddComplianceOwnExpense = in.readDouble();
        this.flag = in.readInt();
    }

    @Override
    public String toString() {
        return JOINER.join(aac999, cka009, bae041, aaz107, cke480,
                aka078, cke011, ake051, ckc077, akc254,
                ckc345, detailSum, complianceOwnExpense, akc254AddComplianceOwnExpense, sumAkc254,
                sumComplianceOwnExpense, sumAkc254AddComplianceOwnExpense, akc254Compensate, akc254AddCOECompensate);
    }

    @Override
    public int compareTo(PretreatmentDataBean o) {
        int compare = this.aac999.compareToIgnoreCase(o.getAac999());
        return compare == 0 ? (Long.compare(cke011, o.getCke011()) == 0 ? cka009.compareTo(o.getCka009()) : Long.compare(cke011, o.getCke011())) : compare;
    }

    /**
     * 约定顺序的读取数据
     *
     * @param arr
     */
    public void loadDate(String[] arr) {
        this.aac999 = arr[0];
        this.cka009 = arr[1];
        this.bae041 = arr[2];
        this.aaz107 = arr[3];
        this.cke480 = arr[4];

        this.aka078 = arr[5];
        this.cke011 = Long.parseLong(arr[6]);
        this.ake051 = arr[7];
        this.ckc077 = arr[8];
        this.akc254 = Double.parseDouble(arr[9]);

        this.ckc345 = arr[10];
        this.detailSum = arr[11];
        this.complianceOwnExpense = Double.parseDouble(arr[12]);
        this.akc254AddComplianceOwnExpense = Double.parseDouble(arr[13]);
    }

    public static void main(String[] args) {
        System.out.println(String.format("%-12s", "name") + String.format("%-12s", "name"));
    }
}
